const CostModel = require('../models/costModel')
class CostController {
    // 学生缴费记录添加
    static async add(req, res) {
        let { date, student_id, cost } = req.body
        try {
            let results = await CostModel.add(date, student_id, cost)
            console.log(results)
            res.json({ code: 0, msg: "学生缴费记录添加成功！", results })
        } catch (error) {
            console.log(error)
            res.json({ code: 0, msg: error })
        }
    }
    // 学生缴费记录的列表搜索数据请求
    static async list(req, res) {
        let { student_name, student_phone, ed_sys, student_program, page_size, page } = req.query
        // 检查必要参数是否存在
        if (!page_size || !page) {
            return res.status(400).json({ code: -1, msg: "缺少必要参数" });
        }
        try {
            let results = await CostModel.list(student_name, student_phone, Number(ed_sys), student_program, Number(page_size), Number(page))
            console.log(results)
            res.json({ code: 0, msg: "学生缴费记录的列表搜索数据请求成功！", results })
        } catch (error) {
            console.log(error)
            res.json({ code: 0, msg: error })
        }
    }
    // 学生缴费记录删除-软删除
    static async del_f(req, res) {
        let { id } = req.query
        if (!id) {
            return res.status(400).json({ code: -1, msg: "缺少必要参数" });
        }
        try {
            let results = await CostModel.del_f(id)
            console.log(results)
            res.json({ code: 0, msg: "学生缴费记录删除成功！", results })
        } catch (error) {
            console.log(error)
            res.json({ code: 0, msg: error })
        }
    }
    // 学生缴费记录删除-真删除
    static async del_t(req, res) {
        let { id } = req.query
        if (!id) {
            return res.status(400).json({ code: -1, msg: "缺少必要参数" });
        }
        try {
            let results = await CostModel.del_t(id)
            console.log(results)
            res.json({ code: 0, msg: "学生缴费记录删除成功！", results })
        } catch (error) {
            console.log(error)
            res.json({ code: 0, msg: error })
        }
    }
    // 学生缴费记录的获取数据
    static async get(req, res) {
        let { id } = req.query
        if (!id) {
            return res.status(400).json({ code: -1, msg: "缺少必要参数" });
        }
        try {
            let results = await CostModel.get(id)
            console.log(results)
            res.json({ code: 0, msg: "学生缴费记录的获取数据成功！", results })
        } catch (error) {
            console.log(error)
            res.json({ code: 0, msg: error })
        }
    }
    // 学生缴费记录的设置数据
    static async set(req, res) {
        let { id, date, cost } = req.body
        if (!id) {
            return res.status(400).json({ code: -1, msg: "缺少必要参数" });
        }
        try {
            let results = await CostModel.set(id, date, cost)
            console.log(results)
            res.json({ code: 0, msg: "学生缴费记录的获取数据成功！", results })
        } catch (error) {
            console.log(error)
            res.json({ code: 0, msg: error })
        }
    }
}
module.exports = CostController;